package create.prototype;

import java.util.Hashtable;

/**
 * @author yeyangtao
 * @date 2020/6/2 19:12
 */
public class ShapeCache {
    private static Hashtable<String,Shape> shapeMap
            = new Hashtable<>();

    public static Shape getShape(String shapeId){
        Shape cacheShape = shapeMap.get(shapeId);
        return (Shape) cacheShape.clone();
    }
    public static void loadCache(){
        Square square = new Square();
        square.setId("1");
        shapeMap.put(square.getId(),square);

        Rectangle rectangle = new Rectangle();
        rectangle.setId("2");
        shapeMap.put(rectangle.getId(),rectangle);
    }
}
